<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Title</title>
  </head>
  <body>
    <script>
      Function.prototype.myBind = function (obj) {
        var args = Array.prototype.slice.call(arguments, 1);
        var context = this;
        var bound = function (newArgs) {
          if (newArgs === undefined) {
            return context.apply(obj, args);
          }
          args = args.concat(Array.prototype.slice.call(newArgs));
          return context.apply(obj, args);
        };
        bound.prototype = Object.create(this.prototype);
        return bound;
      };

      var name = "Jack";
      function person(age, job, gender) {
        console.log(this.name, age, job, gender);
      }
      var Yve = { name: "Yvette" };
      let result = person.bind(Yve, 22, "enginner")("female");



/*
      Function.prototype.bind = function(context) {
        if(typeof this !== "function"){
          throw new TypeError("not a function");
        }
        let self = this;
        let args = [...arguments].slice(1);
        function Fn() {}
        Fn.prototype = this.prototype;
        let bound = function() {
          let res = [...args, ...arguments]; //bind传递的参数和函数调用时传递的参数拼接
          context = this instanceof Fn ? this : context || this;
          return self.apply(context, res);
        };
        //原型链
        bound.prototype = new Fn();
        return bound;
      };*/

    </script>
  </body>
</html>
